<template>
	<view class='main'>
		
		<view class='tools' >
			<xd-tools :power='power' :fileds='fileds'  :data='data' ></xd-tools>
			
		</view>
		<view class='search' >
			<xd-search :fileds='fileds' @submit='submitClicked'></xd-search>
			
		</view>
		<view class='table' >
			<xd-table :fileds='fileds'  :data='data' @showColsChanged="colsChanged" 
			:tableParams='queryParams' @pageSizeChange="pageSizeChange"
			@currentIndexChange="currentIndexChange"></xd-table>
			
		</view>
	</view>
	
</template>
<script setup>
	import { computed,ref } from "vue";
	import  store  from "@/store/index.js"
	import { onLoad } from '@dcloudio/uni-app'
	import {apiGetSamplers} from "@/api/apis.js"
	
	const parms =ref({}) //raw  类别
	
	const fileds=ref([])
	
	const data=ref([])
	const power = computed(() =>{
		const t={}
		
		//store:raw:sample:remove:yp
		t.add={
				power:'store:'+parms.value.lb+':sample:add:'+parms.value.sx,
				url:{
					url:"/pages/quality/sample/add",
					url_path:'?sx='+parms.value.sx+'&lb='+parms.value.lb
				}
			}
		t.remove={
				power:'store:'+parms.value.lb+':sample:remove:'+parms.value.sx,
				url:"/pages/quality/sample/add"
			}
		t.show={
				power:'store:'+parms.value.lb+':sample:main:'+parms.value.sx,
				url:"/pages/quality/sample/add"
			}
		t.edit={
				power:'store:'+parms.value.lb+':sample:edit:'+parms.value.sx,
				url:"/pages/quality/sample/add"
			}
		
		return t
		
	})
	
	//定义data参数
	const queryParams =ref({
		page:1,
		limit:10,
		count:0,
		total_count:0
		
	})
	
	onLoad((e) => {
	        
		  let {id=null,name=null,lb=null,sx=null} = e;		  
		  
		  parms.value=e		  
		  getClassList()	
	    })	
	//获取分类列表网络数据
	const getClassList = async ()=>{
		console.log('getClassList',parms.value)
				
		let res;
		if(queryParams.value) res = await apiGetSamplers(queryParams.value);
		fileds.value=res.fileds
		data.value=res.data	
		queryParams.value.count=res.count
		queryParams.value.total_count=res.total_count
		//获取要显示的列
		let items = uni.getStorageSync('store:'+parms.value.lb+':sample:main:'+parms.value.sx+':showcolumns') 
		if (items){		
			
			fileds.value.forEach((item)=>{
				items.forEach((it)=>{
					
					if (item.value===it.value){
						item.show=it.show 
						
					}
				})
			})
			
		}else{
			fileds.value.forEach((item)=>{
								item.show=true
							})
			
			uni.setStorageSync('store:'+parms.value.lb+':sample:main:'+parms.value.sx+':showcolumns',fileds.value) 
			
		}
		
		
				
		
	}
	
	const submitClicked = (e)=>{
		
		if (e.contions_value) {queryParams.value.contions=e}
		else{
			
			delete queryParams.value.contions
		}
		getClassList()
		
	}
	const colsChanged = (e)=>{
		
		if(e.length){
			
			fileds.value.forEach((item)=>{
				let isture=true
				e.forEach((it)=>{
					if (item.value===it){
						item.show=true
						isture=false
					}
				})
				if (isture){
					item.show=false
				}
				
								
			})
			uni.setStorageSync('store:raw:sample:main:yp:showcolumns',fileds.value) 
		}
	}
	const pageSizeChange = (e)=>{	
		queryParams.value.page=1
		queryParams.value.limit=e
		getClassList()
		
	}
	const currentIndexChange = (e)=>{
		console.log('currentIndexChange',e)
		queryParams.value.page=e.current
		getClassList()
		
	}
</script>

<style lang="scss">
	.main{
		max-width: 100%;
		
		.tools{
			
		}
		.search{
			
		}
		.table{
			width: 100%;
		}
	}
	
	
</style>
